import { defineStore } from 'pinia'
import { getAlarmList,addNewAlarm,addTimeGroup,getAllGroupAlarm,deleteTime,deleteGroupAlarm } from '@/api/timeHttp'

// 所有药品
export const useTimeStore = defineStore('time', {
  state: () => ({
    alarmList:[],
    alarmGroupList:[],
    categoryId:Number
  }),
  
  getters: {
    
  },
  
  actions: {

    async getAlarmList() {
        const {data:{data}} = await getAlarmList()
        console.log(data);
        
        this.alarmList = data
    },
    async addNewAlarm(alarmTime,interval) {
        const time = '2024-10-07 ' + alarmTime + ':00'
        const Interval = interval * 3600
        await addNewAlarm(time,Interval)
        this.getAlarmList()
    },
    async addTimeGroup(id) {
        addTimeGroup(id,this.categoryId)
    },
    async getAllGroupAlarm(){
        const {data:{data}} = await getAllGroupAlarm()
        console.log(data);
        
        this.alarmGroupList = data
    },
    async deleteTime(id){
        console.log(2);
        await deleteTime(id)
    },
    async deleteGroupAlarm(alarmId,categoryId){

        await deleteGroupAlarm(alarmId,categoryId)
    }
}
}) 